home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’95 / Menu Controls / UDrawShapes.h < prev    next >
Encoding:
Text File  |  1995-06-24  |  5.8 KB  |  142 lines  |  [TEXT/MPS ]

  1. // Copyright © 1994-95 by Apple Computer, Inc. All rights reserved.
  2. // UDrawShapes.h
  3.  
  4. // This sample application illustrates numerous features of MacApp and the
  5. // Printing building block.
  6.  
  7. /*-----------------------------------------------------------------------------
  8. The application's windows show a palette at left, and a drawing area to the
  9. right; this is similar to MacDraw and MacPaint.
  10.  
  11. In the windows, the user can draw quadrilaterals and ovals (choosing which
  12. from the palette) and can move already-drawn shapes around.
  13.  
  14. Command-D is used to toggle the availability of a special 'More Debug' menu
  15. in the menu bar, both to illustrate how to have commands on command-keys that
  16. aren't themselves in the menu and how to insert and delete menus dynamically.
  17. Three special debugging commands are only available when this special menu
  18. is inserted.
  19.  
  20. Full Clipboard support is also illustrated, including most features that any
  21. application would be likely to need.  Shapes can be cut or pasted between
  22. documents, and picture-versions of shapes on the Clipboard can be pasted into
  23. other applications such as MacPaint.
  24.  
  25. Printing and Filing are also supported.  Window state is preserved in saved
  26. files.    Filing uses both data and resource forks, to illustrate both
  27. techniques.
  28.  
  29. All commands are undoable.    Commands illustrated include commands to Draw,
  30. commands to move objects around within the view, and commands to change
  31. properties of objects.
  32.  
  33. Hold the OPTION key down while drawing to constrain the drawing to be a
  34. square/circle rather than a general rectangle/oval while sketching.  This
  35. constrains the object being drawn to be a square/circle whose side/diameter
  36. is a horizontal or vertical offset of the mouse from the anchor point,
  37. whichever is SMALLER.  This may feel a bit strange in practice, but it does
  38. illustrate a feature.
  39. -----------------------------------------------------------------------------*/
  40.  
  41. #ifndef __UDRAWSHAPES__
  42. #define __UDRAWSHAPES__
  43.  
  44. #ifndef __UAPPLICATION__
  45. #include <UApplication.h>
  46. #endif
  47.  
  48. #ifndef __USHAPELIST__
  49. #include "UShapeList.h"
  50. #endif
  51.  
  52. //--------------------------------------------------------------------------------------------------
  53.  
  54. class TPatternsMenu;
  55. class TToolsMenu;
  56. class TToolsPalette;
  57.  
  58. //--------------------------------------------------------------------------------------------------
  59. // Constants
  60.  
  61. const unsigned long kSignature    = 'SS05';            // application signature
  62. const unsigned long kDocType    = 'SF05';            // File type for document files 
  63.                                                     // created by this application
  64. const unsigned long kTextFileType = 'TEXT';
  65. const unsigned long kScrapType    = kTextFileType;
  66. const unsigned long kShapeClipType = 'SHAP';        // Clipboard type for my shapes
  67.  
  68. //--------------------------------------------------------------------------------------------------
  69. // Commands                                        
  70. const CommandNumber cPatterns    = 1300;        // Used to enable the Patterns tear-off menu
  71. //const CommandNumber cPatternsMax = cPatterns + kTotalPatterns;
  72.  
  73. const CommandNumber cPickColor    = 1005;        // Use Color Picker for shape's color
  74.  
  75. const CommandNumber cNewShape    = 1010;        // Drawing a new shape
  76. const CommandNumber cMoveShape    = 1011;        // Moving one or more shapes
  77.  
  78. const CommandNumber cChangeShade = 1012;    // Buzz command for "Undo Shade Change"
  79. const CommandNumber cChangeColor = 1013;    // Buzz command for "Undo Color Change"
  80. const CommandNumber cChangeTool  = 1014;    // Buzz command for "Undo Tool Change"
  81.  
  82. const CommandNumber cToggleMoreDebugMenu = 1200; // Command to put up the "More Debug" menu,
  83.                                             // or, if it is already up, to take it down.
  84.                                             // This demonstrates both how to handle commands
  85.                                             // not in the menu bar and how to put entire 
  86.                                             // menus up and take them down dynamically.
  87.  
  88. // The following four commands are only available in the "More Debug" menu,
  89. // which is only accessible if you type Command-D to insert that menu into the menu bar.
  90.  
  91. const CommandNumber cPasteReplacesSelection = 118;    // Debugging: whether pasting into a
  92.                                             // shapeView should supplant any existing
  93.                                             // selection or not. If not, the pastee instead
  94.                                             // is centered in the window.
  95. const CommandNumber cRecalcExtent = 119;    // Debugging: performs immediate recomputation
  96.                                             // of view extent; if gConstrainDrags is false,
  97.                                             // it is possible for a shape to be beyond the
  98.                                             // view border; the view's extent can be refigured
  99.                                             // on demand by using this command
  100. const CommandNumber cConstrainDrags = 120;    // Debugging: whether shape-dragging should be
  101.                                             // constrained so that the entire selection fits
  102.                                             // within the view or not.
  103. const CommandNumber cBetterFeedback = 121;    // Debugging: whether to use the code which
  104.                                             // provides better TrackFeedback
  105.  
  106. //--------------------------------------------------------------------------------------------------
  107. // TShapeApplication
  108. //--------------------------------------------------------------------------------------------------
  109. class TShapeApplication : public TApplication
  110. {
  111.     MA_DECLARE_CLASS;
  112.  
  113.   public:
  114.     TShapeApplication();            // Constructor
  115.  
  116.     void IShapeApplication();
  117.         // Initialize the Application
  118.  
  119.     virtual TDocument *DoMakeDocument(CommandNumber itsCommandNumber, TFile* itsFile);
  120.         // Creates a TShapeDocument
  121.  
  122. #if qDebug
  123.     virtual void DoCommandKeyEvent(TToolboxEvent* event);        // Override
  124.     virtual void DoMenuCommand(CommandNumber aCommandNumber);    // Override 
  125.     virtual void DoSetupMenus();                                // Override
  126. #endif
  127.  
  128.     virtual TView* MakeViewForAlienClipboard();                    // Override
  129. };
  130.  
  131. //--------------------------------------------------------------------------------------------------
  132. // extern Globals
  133.  
  134. //    extern TShapeApplication* gShapeApplication;
  135. extern Boolean            gPasteReplacesSelection;
  136. extern Boolean            gConstrainDrags;
  137. extern short            gStaggerCount;                    // for SimpleStagger
  138. extern CCrsrHandle        gRainbowArrow;
  139. extern Boolean            gBetterFeedback;
  140.  
  141. #endif
  142.